package com.gusti.turnos.util;

import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.Date;
import java.util.List;

import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.gusti.turnos.model.User;

/**
 * 
 * @author gusti
 *
 */
public class EmailUtil {

	private String host;
	private String port;
	private String username;
	private String password;

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	/** --------------------------------------------------
	 *  --------------------------------------------------
	 *  -------------------------------------------------- */

	public static boolean sendNewUserEmail( User user, String decodedPassword ) {

		boolean success = true;
//		try {
//			Session session = getMailSession();
//			MimeMessage message = new MimeMessage(session);
//
//			message.addRecipient( Message.RecipientType.TO, new InternetAddress( user.getEmail() ) );
//
//			String fromAddress = (String) ServerUtil.getInstance().getEnvEntry("systemEmailAddress");
//			String fromName = (String) ServerUtil.getInstance().getEnvEntry("systemEmailName");
//			String subject = (String) ServerUtil.getInstance().getEnvEntry("newUserSubject");
//			String loginURL = ServerUtil.getInstance().getApplicationURL();
//
//			message.setFrom( new InternetAddress( fromAddress, fromName ) );
//			message.setSubject( subject );
//
//			String content = (String) ServerUtil.getInstance().getEnvEntry("newUserContent");
//			content = MessageFormat.format( content, new Object[] { user.getUserId(), tempPassword, loginURL } );
//			message.setText( conten t);
//			message.setSentDate( new Date() );
//
//			Transport tr = session.getTransport("smtp");
//			tr.connect( session.getProperty("mail.smtp.host"), session.getProperty("mail.smtp.user"), session.getProperty("mail.smtp.password") );
//			message.saveChanges();
//			tr.sendMessage( message, message.getAllRecipients() );
//			tr.close();			
//
//		} catch( UnsupportedEncodingException e ) {
//			throw new RuntimeException( e );
//		} catch( MessagingException e ) {
//			success = false;
//		}

		return success;
	}
}
